package com.base.monitor.admin.controller.manage;

import com.base.monitor.admin.service.AuthService;
import com.base.monitor.model.model.biz.collect.entity.Blacklist;
import com.base.monitor.module.biz.context.ClientContext;
import com.base.monitor.module.biz.properties.NetworkProperties;
import com.base.monitor.module.biz.service.cfg.ParamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;
import java.util.Map;

/**
 * 针对thymeleaf的同步渲染控制器
 * @author: tsing
 * @create: 2021-03-04 21:56
 */
@Controller
@EnableConfigurationProperties(NetworkProperties.class)
public class RenderController {

    @Autowired
    private NetworkProperties networkProperties;

    @Autowired
    private ParamService paramService;

    /**
     * 跳转至登录页
     * @return
     */
    @GetMapping("/login")
    public String login() {
        return "/login";
    }

    /**
     * 跳转至首页
     * @return
     */
    @GetMapping({"/admin", "/"})
    public String admin() {
        return "/index";
    }

    /**
     * 请求首页的数据
     * @return
     */
    @GetMapping("home")
    public String home() {
        return "/home/dashboard";
    }

    /**
     * 请求参数配置页
     * @return
     */
    @GetMapping("/params")
    public String params(Model model) {
        Map<String, String> param = paramService.getParam();
        model.addAllAttributes(param);
        return "/param/setting";
    }

    /**
     * 请求连接列表页
     * @return
     */
    @GetMapping("/channels")
    public String channels() {
        return "/channel/list";
    }

    /**
     * 请求黑名单页
     * @return
     */
    @GetMapping("/blacks")
    public String blacks(Model model) {
        List<Blacklist> blacklist = ClientContext.getBlacklist();
        model.addAttribute("blacklistList", blacklist);
        model.addAttribute("blacklistListSize", blacklist.size());
        return "/blacklist/list";
    }

    /**
     * 请求用户页
     * @return
     */
    @GetMapping("/users")
    public String users() {
        return "/user/list";
    }

    /**
     * 请求网关页
     * @return
     */
    @GetMapping("/gateways")
    public String gateways() {
        return "/gateway/list";
    }

    /**
     * 请求指标页
     * @return
     */
    @GetMapping("/indicators")
    public String indicators(Model model) {
        return "/indicator/list";
    }

    /**
     * 请求服务端页
     * @return
     */
    @GetMapping("/servers")
    public String servers(Model model) {
        model.addAttribute("serverPort", networkProperties.getPort());
        return "/server/list";
    }

    /**
     * 数据请求页
     * @return
     */
    @GetMapping("/collects")
    public String collects(Model model) {
        return "/collect/list";
    }
}
